<template>
  <div class="purchase-detail-container">
    <!-- 页面标题 -->
    <div class="page-header">
      <h1>求购详情</h1>
      <p class="subtitle">单号: #{{ purchaseData.purchaseId }}</p>
    </div>

    <!-- 主要内容区域 -->
    <div class="content-wrapper">
      <!-- 左侧设备信息 -->
      <div class="left-section">
        <!-- 基本信息卡片 -->
        <el-card class="info-card" shadow="hover">
          <template #header>
            <div class="card-header">
              <span class="card-title">设备信息</span>
              <el-tag :type="purchaseData.purchaseStatus ? 'success' : 'info'">
                {{ purchaseData.purchaseStatus ? '有效' : '已关闭' }}
              </el-tag>
            </div>
          </template>

          <el-descriptions :column="1" border>
            <el-descriptions-item label="设备品牌">
              <el-tag type="primary">{{ purchaseData.brand }}</el-tag>
            </el-descriptions-item>
            
            <el-descriptions-item label="设备型号">
              <span class="highlight-text">{{ purchaseData.model }}</span>
            </el-descriptions-item>
            
            <el-descriptions-item label="设备类型">
              <el-tag>{{ purchaseData.typeName }}</el-tag>
            </el-descriptions-item>
            
            <el-descriptions-item label="期望年份">
              <span class="year-badge">{{ purchaseData.expectedYear }}年</span>
            </el-descriptions-item>
            
            <el-descriptions-item label="期望价格">
              <span class="price-text">¥{{ formatPrice(purchaseData.expectedPrice) }}</span>
            </el-descriptions-item>
          </el-descriptions>
        </el-card>

        <!-- 参数要求卡片 -->
        <el-card class="info-card" shadow="hover">
          <template #header>
            <div class="card-header">
              <span class="card-title">参数要求</span>
            </div>
          </template>
          
          <div class="requirement-content">
            <p>{{ purchaseData.parameterRequirement }}</p>
          </div>
        </el-card>
      </div>

      <!-- 右侧联系信息 -->
      <div class="right-section">
        <!-- 联系人信息卡片 -->
        <el-card class="info-card" shadow="hover">
          <template #header>
            <div class="card-header">
              <span class="card-title">联系人信息</span>
              <el-icon><User /></el-icon>
            </div>
          </template>

          <el-descriptions :column="1">
            <el-descriptions-item label="联系人">
              <div class="contact-item">
                <el-icon><Avatar /></el-icon>
                <span>{{ purchaseData.contactName }}</span>
              </div>
            </el-descriptions-item>
            
            <el-descriptions-item label="联系电话">
              <div class="contact-item">
                <el-icon><Phone /></el-icon>
                <span>{{ purchaseData.contactPhone }}</span>
              </div>
            </el-descriptions-item>
            
            <el-descriptions-item label="业务员ID">
              <el-tag type="info">#{{ purchaseData.businessmanId }}</el-tag>
            </el-descriptions-item>
          </el-descriptions>

          <div class="action-buttons">
            <el-button type="primary" :icon="Phone" @click="yewu(purchaseData.businessmanId)">联系业务员</el-button>
            
          </div>
        </el-card>

        <!-- 时间信息卡片 -->
        <el-card class="info-card" shadow="hover">
          <template #header>
            <div class="card-header">
              <span class="card-title">时间信息</span>
              <el-icon><Clock /></el-icon>
            </div>
          </template>

          <el-timeline>
            <el-timeline-item
              :timestamp="formatTime(purchaseData.releaseTime)"
              type="primary"
            >
              需求发布
            </el-timeline-item>
            <el-timeline-item
              :timestamp="formatTime(purchaseData.createTime)"
            >
              创建时间
            </el-timeline-item>
            <el-timeline-item
              :timestamp="formatTime(purchaseData.updateTime)"
              type="success"
            >
              最后更新
            </el-timeline-item>
          </el-timeline>
        </el-card>
      </div>
    </div>

    <!-- 底部操作栏 -->
    <el-dialog v-model="dialogVisible9" title="业务员信息" width="30%">
              <el-card shadow="hover">
                <el-descriptions :column="1">
                  <el-descriptions-item label="业务员ID">
                    <el-tag type="info">#{{ pur.businessmanId }}</el-tag>
                  </el-descriptions-item>
                  <el-descriptions-item label="业务员姓名">
                    <span class="highlight-text">{{ pur.name }}</span>
                  </el-descriptions-item>
                  <el-descriptions-item label="手机号">
                    <span class="highlight-text">{{ pur.phone }}</span>
                  </el-descriptions-item>
                </el-descriptions>
              </el-card>
              <template #footer>
                <el-button type="primary" @click="dialogVisible9 = false">关闭</el-button>
              </template>
              </el-dialog>
  </div>
</template>

<script setup>
import { ref,onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useRoute } from 'vue-router'
import { useCounterStore } from '@/stores/counter'
import axios from 'axios'
import { 
  User, 
  Phone, 
  Clock, 
  Avatar,
  ChatDotRound,
  Star,
  Share,
  Printer,
  ShoppingCart
} from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'

const router = useRouter()
const route = useRoute()

//模态框
const dialogVisible9 = ref(false)
onMounted(async() => { 
  console.log('purchaseData',useCounterStore().purchaseData)
  purchaseData.value=useCounterStore().purchaseData
})
//业务员信息
const yewu =async(businessmanId)=>{ 
  //判断登录
  if (useCounterStore().token==null || useCounterStore().token=='') {
    ElMessage.warning('请先登录')
  }else{
  dialogVisible9.value = true
  const res = await axios.get(`eduservice/businessman/${businessmanId}`)
  pur.value=res.data.data.businessman
  }
}
const purchaseData = ref({

})
const pur=ref({})

// 格式化价格显示
const formatPrice = (price) => {
  return new Intl.NumberFormat('zh-CN').format(price)
}

// 格式化时间显示
const formatTime = (timeString) => {
  return new Date(timeString).toLocaleString('zh-CN')
}
</script>

<style scoped>
.purchase-detail-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background: #f5f7fa;
  min-height: 100vh;
}

.page-header {
  text-align: center;
  margin-bottom: 30px;
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.page-header h1 {
  color: #303133;
  margin-bottom: 8px;
  font-size: 28px;
}

.subtitle {
  color: #909399;
  font-size: 14px;
}

.content-wrapper {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 20px;
  margin-bottom: 20px;
}

.info-card {
  border-radius: 8px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
}

.highlight-text {
  font-size: 18px;
  font-weight: 600;
  color: #409EFF;
}

.year-badge {
  background: #f0f9ff;
  color: #409EFF;
  padding: 4px 8px;
  border-radius: 4px;
  font-weight: 600;
}

.price-text {
  font-size: 20px;
  font-weight: 700;
  color: #f56c6c;
}

.requirement-content {
  line-height: 1.6;
  color: #606266;
  font-size: 14px;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.action-buttons {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.action-footer {
  background: white;
  padding: 20px;
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .content-wrapper {
    grid-template-columns: 1fr;
  }
  
  .page-header h1 {
    font-size: 24px;
  }
  
  .action-buttons {
    flex-direction: column;
  }
}

/* 动画效果 */
.info-card {
  transition: all 0.3s ease;
}

.info-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
</style>